home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / as02.arc / SCRNSAVE.ASM < prev    next >
Assembly Source File  |  1985-08-06  |  9KB  |  250 lines

  1.  
  2. ;-----------------------------------------------------------------------------;
  3. ;     These are the interrupt vectors for the clock, keyboard, and video      ;
  4. ;     io calls.                                   ;
  5. ;-----------------------------------------------------------------------------;
  6.  
  7. vectors       segment at 0h
  8.      org      10h * 2
  9. time_of_day_vector1    label word     ;clock interrupt, 18.2 per second
  10.      org      11h * 2
  11. time_of_day_vector2    label word
  12.      org      12h * 2
  13. keyboard_int_vector1    label word
  14.      org      13h * 2
  15. keyboard_int_vector2    label word
  16.      org      20h * 2
  17. video_io_vector1    label word
  18.      org      21h * 2
  19. video_io_vector2    label word
  20. vectors       ends
  21.  
  22. ;-----------------------------------------------------------------------------;
  23. ;     This is the data area starting at 400h used by the ROM BIOS          ;
  24. ;     routines.  ADDR_6845 contains the base address, 3x4, of the current     ;
  25. ;     display adapter and CRT_MODE_SET contains the current setting of the    ;
  26. ;     display mode - the 3x8 register.    Here x is B for the monochrome          ;
  27. ;     display adapter, and D for the color-graphics adapter.              ;
  28. ;-----------------------------------------------------------------------------;
  29.  
  30. rom_bios_data      segment at 40h
  31.      org      10h
  32. equip_flag      dw       ?           ;used to determine display type
  33.      org      60h
  34. cursor_mode      dw       ?           ;current cursor mode (start, stop line)
  35.      org      63h
  36. addr_6845      dw       ?           ;base address for active display card
  37. crt_mode_set      db       ?           ;current setting of 3x8 register
  38. rom_bios_data      ends
  39.  
  40. ;-----------------------------------------------------------------------------;
  41. ;     this is the start of the local data and executable code              ;
  42. ;-----------------------------------------------------------------------------;
  43.  
  44. code_seg      segment
  45.      assume   cs:code_seg
  46.      org      100h
  47. begin:     jmp      init_vectors           ;initialize vectors and attach to DOS
  48.  
  49. rom_time_of_day_int1 dw    ?           ;addresses for rom routines
  50. rom_time_of_day_int2 dw    ?
  51. rom_keyboard_int1    dw    ?
  52. rom_keyboard_int2    dw    ?
  53. rom_video_io_int1    dw    ?
  54. rom_video_io_int2    dw    ?
  55. timer_delay         dw    0ccch       ;delay before turning off video
  56. three_min_counter    dw    ?           ;clock ticks in three minutes
  57.  
  58. old_cursor_type      dw    0           ;hold the old cursor type
  59.  
  60. ;-----------------------------------------------------------------------------;
  61. ;     turn the video display off after three minutes of no use.           ;
  62. ;                                          ;
  63. ;     calls:  rom_time_of_day_int                          ;
  64. ;     reads:  addr_6845, crt_set_mode                          ;
  65. ;     writes: three_min_counter, old_cursor_type                  ;
  66. ;-----------------------------------------------------------------------------;
  67.  
  68. intercept_time_of_day       proc     near
  69.      push         ax
  70.      push         ds
  71.      mov         ax, cs           ;set data segment to current segment
  72.      mov         ds, ax
  73.      assume      ds:code_seg
  74.      dec         three_min_counter ;Have 3 minutes elapsed
  75.      jz         turn_video_off    ;yes, turn video off
  76.      jg         goto_rom_time_of_day          ;no, keep video on
  77.      mov         three_min_counter, 0          ;video is off, reset cnt
  78. goto_rom_time_of_day:
  79.      pop         ds
  80.      pop         ax
  81.      assume      ds:nothing
  82.      jmp         rom_time_of_day_int1
  83. turn_video_off:
  84.      assume      ds:code_seg
  85.      push         bx
  86.      push         cx
  87.      push         dx
  88.      mov         ah, 3           ;get current cursor type into CX
  89.      pushf                   ;push flags to simulate INT with CALL
  90.      call         rom_video_io_int1 ;must use call since INT 10 points here
  91.      mov         old_cursor_type, cx          ;and save it.
  92.      mov         ch, 0fh           ;now remove cursor from screen
  93.      mov         cl, 0
  94.      mov         ah, 1
  95.      pushf
  96.      call         rom_video_io_int1
  97.      pop         dx
  98.      pop         cx
  99.      pop         bx
  100.      push         dx
  101.      mov         ax, rom_bios_data
  102.      mov         ds, ax
  103.      assume      ds:rom_bios_data
  104.      mov         dx, addr_6845     ;get base address for display adapter
  105.      add         dx, 4           ;IO address for 3x8 register
  106.      mov         al, crt_mode_set
  107.      and         al, 0f7h           ;turn video off
  108.      out         dx, al
  109.      pop         dx
  110.      jmp         goto_rom_time_of_day
  111. intercept_time_of_day       endp
  112.  
  113. ;-----------------------------------------------------------------------------;
  114. ;     This procedure resets the timer count to 0ccch and turns the display ;
  115. ;     on if it was off.                               ;
  116. ;-----------------------------------------------------------------------------;
  117.  
  118. reset_counter      proc       near
  119.      push         ax
  120.      push         dx
  121.      push         ds
  122.      mov         ax, cs
  123.      mov         ds, ax
  124.      assume      ds:code_seg
  125.      cmp         three_min_counter, 0          ;was the display off?
  126.      jg         video_not_off     ;no, then reset counter
  127.      push         ds            ;yes, then turn video back on
  128.      mov         ax, rom_bios_data
  129.      mov         ds, ax
  130.      assume      ds:rom_bios_data
  131.      mov         dx, addr_6845     ;get base address for display adapter
  132.      add         dx, 4           ;IO address for 3x8 register
  133.      mov         al, crt_mode_set
  134.      or         al, 8           ;turn video on again
  135.      out         dx, al
  136.      pop         ds
  137.      assume      ds:code_seg
  138.      push         cx            ;now restore the cursor
  139.      mov         cx, old_cursor_type
  140.      mov         ah, 1           ;restore the old cursor type
  141.      pushf
  142.      call         rom_video_io_int1
  143.      pop         cx
  144. video_not_off:
  145.      mov         ax, timer_delay
  146.      mov         three_min_counter, ax
  147.      pop         ds
  148.      pop         dx
  149.      pop         ax
  150.      ret
  151. reset_counter      endp
  152.  
  153. intercept_keyboard_int       proc     near
  154.      assume      ds:nothing
  155.      call         reset_counter     ;reset the timeout counter
  156.      jmp         rom_keyboard_int1 ;pass control to rom routine
  157. intercept_keyboard_int       endp
  158.  
  159. ;-----------------------------------------------------------------------------;
  160. ;     This procedure resets the cursor type to the default type for the    ;
  161. ;     display adapter in use: 607H for the color/graphics adapter and          ;
  162. ;     0B0CH for the monochrome display adapter.                   ;
  163. ;-----------------------------------------------------------------------------;
  164.  
  165. set_cursor_mode   proc       near
  166.      push         ax
  167.      push         cx
  168.      push         ds
  169.      mov         ax, rom_bios_data
  170.      mov         ds, ax           ;point to ROM BIOS data area
  171.      assume      ds:rom_bios_data
  172.      mov         ax, equip_flag    ;determine which adapter is active
  173.      and         al, 30h           ;isolate adapter information
  174.      mov         cx, 607h           ;set for color/graphics adapter
  175.      cmp         al, 30h           ;is monochrome display active
  176.      jne         color_active      ;no, set cursor type
  177.      mov         cx, 0B0Ch           ;cursor mode for monochrome display
  178. color_active:
  179.      mov         ah, 1
  180.      pushf
  181.      call         rom_video_io_int1
  182.      pop         ds
  183.      pop         cx
  184.      pop         ax
  185.      ret
  186. set_cursor_mode   endp
  187.  
  188. ;-----------------------------------------------------------------------------;
  189. ;     This procedure resets the time-out counter, and passes control on    ;
  190. ;     to the ROM_VIDEO_IO routines.                          ;
  191. ;-----------------------------------------------------------------------------;
  192.  
  193. intercept_video_io    proc     near
  194.      assume      ds:nothing
  195.      call         reset_counter     ;reset time-out counter
  196.      pushf
  197.      call         rom_video_io_int1
  198.      or         ah, ah           ;asking for set-mode function?
  199.      jnz         not_mode_set      ;no, then return
  200.      call         set_cursor_mode   ;yes, then set cursor mode to default
  201. not_mode_set:
  202.      iret
  203. intercept_video_io    endp
  204.  
  205. ;-----------------------------------------------------------------------------;
  206. ;     This procedure initializes the interrupt vectors.              ;
  207. ;-----------------------------------------------------------------------------;
  208.  
  209. init_vectors      proc       near
  210.      assume      ds:vectors
  211.      mov         ax, vectors       ;set up the data segment for vectors
  212.      mov         ds, ax
  213.      cli                   ;don't allow interrupts
  214.  
  215.      mov         ax, time_of_day_vector1          ;save addr / BIOS routine
  216.      mov         rom_time_of_day_int1, ax
  217.      mov         ax, time_of_day_vector2
  218.      mov         rom_time_of_day_int2, ax
  219.      mov         time_of_day_vector1, offset intercept_time_of_day
  220.      mov         time_of_day_vector2, cs
  221.  
  222.      mov         ax, keyboard_int_vector1
  223.      mov         rom_keyboard_int1, ax
  224.      mov         ax, keyboard_int_vector2
  225.      mov         rom_keyboard_int2, ax
  226.      mov         keyboard_int_vector1, offset intercept_keyboard_int
  227.      mov         keyboard_int_vector2, cs
  228.  
  229.      mov         ax, video_io_vector1
  230.      mov         rom_video_io_int1, ax
  231.      mov         ax, video_io_vector2
  232.      mov         rom_video_io_int2, ax
  233.      mov         video_io_vector1, offset intercept_video_io
  234.      mov         video_io_vector2, cs
  235.  
  236.      mov         ax, timer_delay   ;set the delay to 3 minutes
  237.      mov         three_min_counter, ax
  238.  
  239.      sti                   ;allow interrupts again
  240.      call         set_cursor_mode   ;set cursor mode to default
  241.      mov         dx, offset init_vectors          ;end of resident portion
  242.      int         27h           ;terminate but stay resident
  243. init_vectors      endp
  244.  
  245. code_seg      ends
  246.  
  247.      end         begin
  248.  
  249.  
  250.